package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.UserPhotoAlbum;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IUserPhotoAlbumService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-25 13:06:33
 */
@Controller
@RequestMapping("/userPhotoAlbum")
public class UserPhotoAlbumController extends BaseController {

    private String PREFIX = "/user/userPhotoAlbum/";

    @Autowired
    private IUserPhotoAlbumService userPhotoAlbumService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userPhotoAlbum.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userPhotoAlbum_add")
    public String userPhotoAlbumAdd() {
        return PREFIX + "userPhotoAlbum_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userPhotoAlbum_update/{userPhotoAlbumId}")
    public String userPhotoAlbumUpdate(@PathVariable Long userPhotoAlbumId, Model model) {
        UserPhotoAlbum userPhotoAlbum = userPhotoAlbumService.selectById(userPhotoAlbumId);
        model.addAttribute("item",userPhotoAlbum);
        LogObjectHolder.me().set(userPhotoAlbum);
        return PREFIX + "userPhotoAlbum_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userPhotoAlbumService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserPhotoAlbum userPhotoAlbum) {
        userPhotoAlbumService.insert(userPhotoAlbum);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long userPhotoAlbumId) {
        userPhotoAlbumService.deleteById(userPhotoAlbumId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserPhotoAlbum userPhotoAlbum) {
        userPhotoAlbumService.updateById(userPhotoAlbum);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userPhotoAlbumId}")
    @ResponseBody
    public Object detail(@PathVariable("userPhotoAlbumId") Long userPhotoAlbumId) {
        return userPhotoAlbumService.selectById(userPhotoAlbumId);
    }
}
